# -*- coding:utf-8 -*-
# @Time : 2020/6/4 15:38
# @Author : Administrator
# @File : CommunityPage.py
# @Software: PyCharm
# @Motto: good good study,day day up

from Base.BasePage import BasePage
from loguru import logger
from selenium.webdriver.common.by import By
from config.conf import COMMUNITY_URL
from selenium.webdriver.common.keys import Keys
import datetime


class CommunityPage(BasePage):
    # 房间tab
    loc1 = (By.XPATH, "//div[@id='app']//li[2]//a[1]")
    # 動態tab
    loc2 = (By.XPATH, "//div[@id='app']//li[3]//a[1]")
    # 各个tab页面标题
    loc3 = (By.XPATH, "//h3[@class='summary-title']")
    # 发贴按钮
    loc4 = (By.XPATH, "//span[@class='post-button']")
    #  开房按钮
    loc5 = (By.XPATH, "//span[@class='get-room-button']")
    # 推荐页面中的我的关注
    loc6 = (By.XPATH, "//li[@class='community-nav-item']")
    # 動態
    loc7 = (By.XPATH, "//div[@class='publish-card']//div[2]")
    # 设置封面
    loc8 = (By.XPATH, "//p[@class='publish-avatar-input']")
    # 帖子标题
    loc9 = (By.XPATH, "//input[@placeholder='標題']")
    # 帖子输入框
    loc10 = (By.XPATH, "//div[@class='ql-editor ql-blank']")
    # 确定发布
    loc11 = (By.XPATH, "//div[@class='publish-bottom']//span")
    # 帖子类型-动态
    loc12 = (By.XPATH, "//div[@class='publish-card']//div[2]")
    # 帖子类型-帖子
    loc13 = (By.XPATH, "//div[@class='publish-card']//div[1]")
    # 设置封面
    loc14 = (By.XPATH, "//p[@class='publish-avatar-input']")
    # 提示框中的是按钮
    loc15 = (By.XPATH, "//div[@class='kxDialog-bg cancel']//span[@class='kxDialog-btn-confirm']")
    # 发布成功提示  -- 發佈成功，請等待管理員審核
    loc16 = (By.XPATH, "//div[@class='kxDialog-bg alert']//div[@class='kxDialog-content']")
    # 帖子类型选择框
    loc17 = (By.XPATH, "//div[@class='publish-select-container']//div[2]")
    # 视频贴子
    loc18 = (By.XPATH, "//body//div[@class='publish-content']//div//div//div[2]//div[1]//p[2]")
    # 外部视频
    loc19 = (By.XPATH, "//body//div[@class='publish-content']//div//div[@class='publish-card']//div[2]//span[1]")
    # 外部視頻地址
    loc20 = (By.XPATH, "//input[@placeholder='請輸入外部視頻地址']")
    # 申请开房链接
    loc26 = (By.XPATH, "//a[@class='apply-room']")
    # 申请开房页面toast提示
    loc21 = (By.XPATH, "//div[@class='kxlive-toast']")
    # 开房标题
    loc22 = (By.XPATH, "//input[@id='liveTheme']")
    # 開房人數
    loc23 = (By.XPATH, "//input[@id='maxPlayers']")
    # 开始时间
    loc24 = (By.XPATH, "//input[@id='startTime']")
    # 结束时间
    loc25 = (By.XPATH, "//input[@id='endTime']")
    # 提交申请
    loc27 = (By.XPATH, "//div[@id='submit-apply-btn']")
    # 日期选择框清除按钮
    loc28 = (By.XPATH, "//span[@class='laydate-btns-clear']")

    # 打开待测网页
    def open_url(self):
        self.load_url(COMMUNITY_URL)

    # 模拟登录
    def login(self):
        self.open_url()
        self.sleep(3)
        self.add_cookies_test()

    # 点击tab
    def click_tab(self, by, loc):
        self.open_url()
        self.sleep(3)
        self.click(by, loc)
        self.sleep(3)

    # 点击推荐tab页
    def click_recommend(self):
        self.open_url()
        self.sleep(3)
        return self.get_element_text(*self.loc6)

    # 点击房间tab页
    def click_room(self):
        self.click_tab(*self.loc1)
        return self.get_element_text(*self.loc3)

    # 点击动态
    def click_dynamic(self):
        self.click_tab(*self.loc2)
        return self.get_element_text(*self.loc3)

    # 发贴--图文
    def post(self):
        self.open_url()
        self.sleep(3)
        self.add_cookies_test()
        self.click(*self.loc4)
        self.sleep(1)
        self.switch_to_window()
        self.click(*self.loc13)
        self.send_keys(*self.loc9, '测试发贴')
        self.send_keys(*self.loc10, '测试发贴测试发贴测试发贴测试发贴测试发贴测试发贴')
        self.click(*self.loc11)
        self.click(*self.loc15)
        self.sleep(1)
        return self.get_element_text(*self.loc16)

    # 发贴--视频
    def post_video(self):
        self.open_url()
        self.sleep(3)
        self.add_cookies_test()
        self.click(*self.loc4)
        self.sleep(1)
        self.switch_to_window()
        self.click(*self.loc17)
        self.sleep(3)
        self.click(*self.loc18)
        self.sleep(3)
        self.send_keys(*self.loc8, 'F:\\壁纸\\1.png')
        self.sleep(2)
        self.click(*self.loc19)
        self.send_keys(*self.loc9, '测试发贴视频')
        self.send_keys(*self.loc20, "https://v.qq.com/x/page/l09807z03rn.html")
        self.send_keys(*self.loc10, '测试发贴视频测试发贴视频测试发贴视频')
        self.click(*self.loc11)
        self.click(*self.loc15)
        self.sleep(1)
        return self.get_element_text(*self.loc16)

    # 发贴-动态-文字
    def post_dongtai(self):
        self.open_url()
        self.sleep(3)
        self.add_cookies_test()
        self.click(*self.loc4)
        self.sleep(1)
        self.switch_to_window()
        self.click(*self.loc12)
        self.send_keys(*self.loc10, '测试发动态测试发动态测试发动态测试发动态测试发动态')
        self.click(*self.loc11)
        self.click(*self.loc15)
        self.sleep(1)
        return self.get_element_text(*self.loc16)

    # 不输入标题
    def post_no_title(self):
        self.open_url()
        self.sleep(3)
        self.add_cookies_test()
        self.click(*self.loc4)
        self.switch_to_window()
        self.click(*self.loc11)
        return self.get_element_text(*self.loc16)

    # 不输入正文
    def post_no_body(self):
        self.refresh()
        self.sleep(3)
        self.send_keys(*self.loc9, '输入标题')
        self.sleep(3)
        self.click(*self.loc11)
        return self.get_element_text(*self.loc16)

    # 开房不输入标题
    def get_room_no_title(self):
        self.open_url()
        self.sleep(3)
        self.add_cookies_test()
        self.click(*self.loc5)
        self.sleep(3)
        self.switch_to_window()
        self.click(*self.loc26)
        self.sleep(3)
        self.click(*self.loc27)
        return self.get_element_text(*self.loc21)

    # 开房不输入人数
    def get_room_no_person(self):
        self.login()
        self.click(*self.loc5)
        self.sleep(3)
        self.switch_to_window()
        self.click(*self.loc26)
        self.send_keys(*self.loc22, '测试开房')
        self.click(*self.loc27)
        return self.get_element_text(*self.loc21)

    # 开房不输入开始时间
    def get_room_no_start_time(self):
        self.login()
        self.click(*self.loc5)
        self.sleep(3)
        self.switch_to_window()
        self.click(*self.loc26)
        self.sleep(1)
        self.send_keys(*self.loc22, '测试开房')
        self.send_keys(*self.loc23, '10')
        self.click(*self.loc24)
        self.click(*self.loc28)
        self.click(*self.loc27)
        return self.get_element_text(*self.loc21)

    # 开房不输入结束时间
    def get_room_no_end_time(self):
        self.login()
        self.click(*self.loc5)
        self.sleep(3)
        self.switch_to_window()
        self.click(*self.loc26)
        self.sleep(1)
        self.send_keys(*self.loc22, '测试开房')
        self.send_keys(*self.loc23, '10')
        self.click(*self.loc25)
        self.click(*self.loc28)
        self.click(*self.loc27)
        return self.get_element_text(*self.loc21)

    # 申请时间少于1个小时
    def get_room_start_time_less_1(self):
        self.login()
        self.click(*self.loc5)
        self.sleep(3)
        self.switch_to_window()
        self.click(*self.loc26)
        self.sleep(1)
        self.send_keys(*self.loc22, '测试开房')
        self.send_keys(*self.loc23, '10')
        self.click(*self.loc27)
        return self.get_element_text(*self.loc21)

    # 申请时间大于3个小时
    def get_room_start_time_more_3(self):
        self.login()
        self.click(*self.loc5)
        self.sleep(3)
        self.switch_to_window()
        self.click(*self.loc26)
        self.sleep(1)
        self.send_keys(*self.loc22, '测试开房')
        self.send_keys(*self.loc23, '10')
        end_time = (datetime.datetime.now() + datetime.timedelta(hours=10)).strftime('%Y-%m-%d %H:%M:%S')
        self.send_keys(*self.loc25, end_time)
        self.click(*self.loc27)
        return self.get_element_text(*self.loc21)
